package cn.wind.xboot.module.web.controller;

import cn.wind.xboot.core.res.ApiResult;
import cn.wind.xboot.framework.domain.PageVo;
import cn.wind.xboot.logic.cli.dto.CliDto;
import cn.wind.xboot.logic.cli.service.ICliClientService;
import cn.wind.xboot.logic.dto.CountSalesDto;
import cn.wind.xboot.logic.dto.CountTypeDto;
import cn.wind.xboot.logic.dto.OrderGoodsDto;
import cn.wind.xboot.logic.dto.WithdrawRecordsDto;
import cn.wind.xboot.logic.entity.Bank;
import cn.wind.xboot.logic.entity.Order;
import cn.wind.xboot.logic.service.IBankService;
import cn.wind.xboot.logic.service.IOrderGoodsService;
import cn.wind.xboot.logic.service.IOrderService;
import cn.wind.xboot.logic.service.IWithdrawService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 *财务管理
 * @author WangHao
 * @date 2018-12-26
 */
@Slf4j
@RequestMapping("financeManage")
@Controller
public class FinanceManageController {
    @Autowired
    private IOrderService orderService;
    @Autowired
    private IOrderGoodsService orderGoodsService;
    @Autowired
    private IBankService bankService;
    @Autowired
    private IWithdrawService withdrawService;
    @Autowired
    private ICliClientService cliClientService;

    /**
     * 财务管理-消费记录
     * @param  cliId 商户id
     * @param payType 支付类型
     * @param searchName  搜索参数
     */
    @RequestMapping("/consumeRecords")
    @ResponseBody
    public ApiResult consumeRecords(PageVo pageVo,Integer payType, String searchName, Long cliId, String bank, Date createTime){
        //查询出所有已经完成的订单
        Map<String,Object> map = Maps.newHashMap();
        map.put("payType",payType);
        map.put("searchName",searchName);
        map.put("cliId",cliId);
        map.put("bank",bank);
        map.put("createTime",createTime);
        IPage<OrderGoodsDto> page = orderService.findFinished(pageVo.init(),map);
        return ApiResult.Custom().success().add(page);
    }

    /**
     * 财务管理-分类统计-按蔬菜种类统计销售额(每一天)
     */
    @RequestMapping("/countByType")
    @ResponseBody
    public ApiResult countByType(PageVo pageVo){
        Map<String,Object> map = Maps.newHashMap();

        IPage<CountTypeDto> page = orderService.findByType(pageVo.init(),map);
        return ApiResult.Custom().success().add(page);
    }

    /**
     * 财务管理-提现记录
     */
    @RequestMapping("/withdrawRecordsList")
    @ResponseBody
    public ApiResult withdrawRecordsList(PageVo pageVo,String realName,String withdrawBank,String withdrawTime){
        Map<String,Object> map = Maps.newHashMap();
        map.put("realName",realName);
        map.put("withdrawBank",withdrawBank);
        map.put("withdrawTime",withdrawTime);
        IPage<WithdrawRecordsDto> page = withdrawService.findWithdrawRecords(pageVo.init(),map);
        return ApiResult.Custom().success().add(page);
    }

    /**
     * 财务管理-统计今日各类菜的销售量
     */
    @RequestMapping("/countSalesByType")
    @ResponseBody
    public ApiResult countSalesByType(){
       // List<CountSalesDto> list = orderService.countSalesByType();
        return ApiResult.Custom().success().add("");
    }

    /**
     * 查询银行名称
     */
    @RequestMapping("/getBankList")
    @ResponseBody
    public ApiResult getBankList(){
       List<Bank> list = bankService.getBankList();
       return ApiResult.Custom().success().add(list);
    }
    /**
     * 获取所有商户信息
     */
    @RequestMapping("/getAllCli")
    @ResponseBody
    public ApiResult getAllCli(){
        List<CliDto> list = cliClientService.findCliAll();
        return ApiResult.Custom().success().add(list);
    }


}
